#include <iostream>
using namespace std;
const int maxN = 520;
int a[maxN][maxN];
bool used[2][maxN][2 * maxN];
int n;
void solve()
{
	int x, y, i;
	x = y = 1;
	a[x][y] = 0;
	while (x <= n)
	{
		int ok = 0;
		for (i = a[x][y] + 1; i < 2 * n; ++i)
			if (!used[0][x][i] && !used[1][x][i] && !used[0][y][i] && !used[1][y][i])
			{
				a[x][y] = i;
				used[0][x][i] = used[1][x][i] = used[0][y][i] = used[1][y][i] = true;
				++y;
				if (y > n)
				{
					y = 1, ++x;
				}
				a[x][y] = 0;
				ok = 1;
				break;
			}
		if (ok == 0)
		{
			--y;
			if (y == 0)
			{
				y = 0, --x;
			}
			i = a[x][y];
			used[0][x][i] = used[1][x][i] = used[0][y][i] = used[1][y][i] = false;
		}
	}
}

int main()
{
	scanf("%d", &n);
	n = (1 << n);
	memset(used, false, sizeof(used));
	solve();
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j)
			printf("%d ", a[i][j]);
		printf("\n");
	}
	return 0;
}